import { Component, OnInit } from '@angular/core';
import { MerchantcashrecordService } from '../../service/merchantcashrecord.service';
import { NzMessageService } from 'ng-zorro-antd';
import { CommonService } from 'src/app/service/common.service';
import { ComponentBasic } from '../../app.component';
import { RoleRight } from '../../../kalend';
@Component({
  selector: 'app-merchantinfo',
  templateUrl: './cashmanageinfo.component.html',
  styleUrls: ['./cashmanageinfo.component.scss'],
  providers: [MerchantcashrecordService, CommonService]
})
export class CashmanageinfoComponent extends ComponentBasic implements OnInit {
  loading = true;
  pageIndex = 1;
  pageSize = 15;
  total = 1;
  doc: any = {};
  dataSet = [];
  sdate: any;
  edate: any;
  iscontact: any;
  remarks: any;
  auditstatus: any;
  // 提现金额
  cashmoney: any;
  isVisible = false;
  isCrshVisible = false;
  isOkLoading = false;
  LoginUser = RoleRight.getStorage();
  statuslist = [{ key: null, value: '全部' }, { key: 1, value: '审核通过' }, { key: 0, value: '审核中' }, { key: 2, value: '审核拒绝' }];
  constructor( private merchantcashrecord: MerchantcashrecordService, private msg: NzMessageService, private commonservice: CommonService) {
    super();
    super.setLayout(true, true);
  }

  ngOnInit() {

    this.searchData();
  }
  searchData(reset: boolean = false): void {
    this.loading = true;
    this.merchantcashrecord.querybypage({
      offset: this.pageIndex,
      limit: this.pageSize,
      auditstatus: this.auditstatus,
      sdate: this.sdate,
      edate: this.edate

    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows;
    });
  }

  auditpass(id): void {
    this.commonservice.confirm('确定通过本次提现吗?', () => {
      this.merchantcashrecord.audit({ _id: id, AuditStatus: 1 }).then((res) => {
        this.msg.success('审批成功，请及时打款');
        this.searchData();
      });
    })
  }

  auditrefuse(id): void {
    this.commonservice.confirm('确定拒绝本次提现吗?', () => {
      this.merchantcashrecord.audit({ _id: id, AuditStatus: 2 }).then((res) => {
        this.msg.success('已拒绝，无需打款');
        this.searchData();
      });
    })
  }

  cash(id): void {
    this.commonservice.confirm('确定已完成打款吗?', () => {
      this.merchantcashrecord.audit({ _id: id, cashstatus: 1 }).then((res) => {
        this.msg.success('操作成功');
        this.searchData();
      });
    })
  }

  // 确定提交
  handleOk(): void {
    const parm = {
      totalcase: this.cashmoney,
      BankCardNo: this.doc.BankCardNumber,
      merchantid: this.doc._id,
      Bank: this.doc.Bank
    }
    this.merchantcashrecord.create(parm).then((res) => {
      this.searchData();
      this.isVisible = false;
      this.doc = {};
    });

  }

  handleCancel(): void {
    this.isVisible = false;
    this.doc = {};
  }
}
